package avicit.bdp.dms.tdm.rest;

import avicit.bdp.dms.tdm.dto.AssetCatalogAuthSettingDTO;
import avicit.bdp.dms.tdm.service.AssetCatalogAuthSettingService;
import avicit.platform6.api.system.ConvertColumnClient;
import avicit.platform6.commons.utils.StringUtils;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.rest.msg.QueryReqBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "数据目录审核人设置")
@RequestMapping("/api/bdp/dms/catalog/auth/setting/")
public class AssetCatalogAuthSettingRest {

  @Autowired private AssetCatalogAuthSettingService assetCatalogAuthSettingService;

  @Autowired private ConvertColumnClient convertColumnClient;

  /**
   * 按条件不分页查询
   *
   * @param queryReqBean 查询条件
   */
  @PostMapping("/search/v1")
  @ApiOperation(value = "按条件不分页查询")
  public ResponseMsg<List<AssetCatalogAuthSettingDTO>> search(
      @ApiParam(value = "查询条件", name = "queryReqBean") @RequestBody
          QueryReqBean<AssetCatalogAuthSettingDTO> queryReqBean) {
    ResponseMsg<List<AssetCatalogAuthSettingDTO>> responseMsg = new ResponseMsg<>();
    List<AssetCatalogAuthSettingDTO> result = assetCatalogAuthSettingService.searchList(queryReqBean);
    responseMsg.setResponseBody(result);
    return responseMsg;
  }

  /**
   * 保存对象
   *
   * @param list 保存对象
   * @return ResponseMsg<String>
   */
  @PostMapping("/save/v1")
  @ApiOperation(value = "新增对象")
  public ResponseMsg<String> save(@RequestBody List<AssetCatalogAuthSettingDTO> list) {
    ResponseMsg<String> responseMsg = new ResponseMsg<>();
    assetCatalogAuthSettingService.delete();
    for (AssetCatalogAuthSettingDTO dto : list) {
      if (StringUtils.isEmpty(dto.getId())) {
        dto.setOrgIdentity(ThreadContextHelper.getOrgId());
        assetCatalogAuthSettingService.insert(dto);
      }
    }
    return responseMsg;
  }
}
